package edu.hcmus.sow.domain;

import java.io.Serializable;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;

import org.codehaus.jackson.annotate.JsonIgnore;

/**
 */

@Entity
@NamedQueries({
      @NamedQuery(name = "findAllFileAccessRights", query = "select myFileAccessRight from FileAccessRight myFileAccessRight"),
      @NamedQuery(name = "findFileAccessRightById", query = "select myFileAccessRight from FileAccessRight myFileAccessRight where myFileAccessRight.id = ?1"),
      @NamedQuery(name = "findFileAccessRightByPrimaryKey", query = "select myFileAccessRight from FileAccessRight myFileAccessRight where myFileAccessRight.id = ?1") })
@Table(catalog = "sow", name = "file_access_right")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "SharedOnlineWorkspace/edu/hcmus/sow/domain", name = "FileAccessRight")
public class FileAccessRight implements Serializable {
   private static final long serialVersionUID = 1L;

   /**
    */
   @Column(name = "ID", nullable = false)
   @Basic(fetch = FetchType.EAGER)
   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   @XmlElement
   Integer id;

   /**
    */
   @Column(name = "ACCESS_RIGHT", length = 1)
   @Basic(fetch = FetchType.EAGER)
   @XmlElement
   String accessRight;

   /**
    */
   @ManyToOne(fetch = FetchType.LAZY)
   @JoinColumns({ @JoinColumn(name = "USER_ID", referencedColumnName = "ID", nullable = false) })
   @XmlTransient
   User user;
   /**
    */
   @ManyToOne(fetch = FetchType.LAZY)
   @JoinColumns({ @JoinColumn(name = "FILE_ID", referencedColumnName = "ID", nullable = false) })
   @XmlTransient
   File file;

   @Column(name = "USER_ID", updatable = false, insertable = false)
   private Integer userID;

   public Integer getUserID() {
      return userID;
   }

   public void setUserID(Integer userID) {
      this.userID = userID;
   }

   public Integer getFileID() {
      return fileID;
   }

   public void setFileID(Integer fileID) {
      this.fileID = fileID;
   }

   @Column(name = "FILE_ID", updatable = false, insertable = false)
   private Integer fileID;

   /**
    */
   public void setId(Integer id) {
      this.id = id;
   }

   /**
    */
   public Integer getId() {
      return this.id;
   }

   /**
    */
   public String getAccessRight() {
      return accessRight;
   }

   /**
    */
   public void setAccessRight(String accessRight) {
      this.accessRight = accessRight;
   }

   /**
    */
   public void setUser(User user) {
      this.user = user;
   }

   /**
    */
   @JsonIgnore
   public User getUser() {
      return user;
   }

   /**
    */
   public void setFile(File file) {
      this.file = file;
   }

   /**
    */
   @JsonIgnore
   public File getFile() {
      return file;
   }

   /**
    */
   public FileAccessRight() {
   }

   /**
    * Copies the contents of the specified bean into this bean.
    * 
    */
   public void copy(FileAccessRight that) {
      setId(that.getId());
      setAccessRight(that.getAccessRight());
      setUser(that.getUser());
      setFile(that.getFile());
   }

   /**
    * Returns a textual representation of a bean.
    * 
    */
   public String toString() {

      StringBuilder buffer = new StringBuilder();

      buffer.append("id=[").append(id).append("] ");
      buffer.append("accessRight=[").append(accessRight).append("] ");

      return buffer.toString();
   }

   /**
    */
   @Override
   public int hashCode() {
      final int prime = 31;
      int result = 1;
      result = (int) (prime * result + ((id == null) ? 0 : id.hashCode()));
      return result;
   }

   /**
    */
   public boolean equals(Object obj) {
      if (obj == this)
         return true;
      if (!(obj instanceof FileAccessRight))
         return false;
      FileAccessRight equalCheck = (FileAccessRight) obj;
      if ((id == null && equalCheck.id != null) || (id != null && equalCheck.id == null))
         return false;
      if (id != null && !id.equals(equalCheck.id))
         return false;
      return true;
   }
}
